package top.houry;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @Desc
 * @Author houruiyang
 * @Date 2022/10/19
 **/
public class TriangleCount {

    public static void main(String[] args) {
//        int[] s = {3,6,7,4};
//        System.out.println(getTriangleCount(s));

//        List<String> list = new ArrayList<>();
//
//        list.add("b");list.add("c");list.add("d");
//        int size = list.size();
//        for (int i = 0; i < list.size(); i++) {
//            System.out.println(list.remove(i));
//        }

        TreeNode n1 = new TreeNode(1);
        TreeNode n2 = new TreeNode(2);
        TreeNode n3 = new TreeNode(3);
        TreeNode n4 = new TreeNode(4);
        TreeNode n5 = new TreeNode(5);
        TreeNode n6 = new TreeNode(6);
        TreeNode n7 = new TreeNode(7);
        TreeNode n8 = new TreeNode(8);
        TreeNode n9 = new TreeNode(9);
        TreeNode n10 = new TreeNode(10);

        n1.left = n2;
        n1.right = n3;
        n2.left = n4;
        n4.left = n7;
        n4.right=n8;
        n3.left = n5;
        n3.right = n6;
        n6.left = n9;
        n6.right = n10;

        print(n1);

        System.out.println(depth(n1));


    }

    public static int getTriangleCount(int[] s) {
        if (null == s || 0 == s.length) {
            return 0;
        }
        // 3 4 6 7
        Arrays.sort(s);

        int total = 0;
        for (int k = s.length - 1; k >=2; k--)  {
            int start = 0;
            int end = k-1;
            while (start < end) {
                if (s[start] + s[end] > s[k]) {
                    total += (end - start);
                    end--;
                } else {
                    start++;
                }
            }
        }
        return total;
    }


    public static int depth(TreeNode root) {
        if (null == root) {
            return 0;
        }
        System.out.println(root.value);
        int left = depth(root.left);
        int right = depth(root.right);

        return Math.max(left, right) +1;
    }

    public static void print(TreeNode root) {
        if (null == root) {
            return;
        }
        System.out.println(root.value + "");
        print(root.left);
        print(root.right);
    }

}


class TreeNode {
    int value;
    TreeNode left;
    TreeNode right;

    TreeNode(int value){
        this.value = value;
    }
}
